<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath }/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>
<link id="easyuiTheme" rel="stylesheet" type="text/css"	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/outOfBounds.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/common.js" type="text/javascript"></script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true">
	
	<div data-options="region:'center'" style="padding:5px">
	<table class="easyui-datagrid" id="articleList"
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'${pageContext.request.contextPath }/admin/vipuser/list.do',method:'get',pageSize:30,toolbar:toolbar,fitColumns:true">
    	<%--
		<input id="ss" class="easyui-searchbox" style="width: 300px" data-options="searcher:doSearchArticle,prompt:'请输入要查找的id',menu:'#mm'"/>
		--%>
    <thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'id',width:80,align:'center'">id</th>
            <th data-options="field:'name',width:100,align:'center'">姓名</th>
			<th data-options="field:'headImg',width:100,align:'center',formatter:function(val, rec){
            	if(val == null) {return ;}
            	var result = '<img src=' + val + ' onclick=javascript:loadImg(this) width=50px height=50px/>';
            	return result;
            }">头像</th>
            <th data-options="field:'job',width:150,align:'center'">公司职务</th>
			<%--会员职称（1-理事会主席 2-理事会荣誉理事长 3-理事会特别顾问 4-理事会理事长 5-理事）--%>
			<th data-options="field:'levelname',width:100,align:'center',formatter:function(val, rec){
            	if(val == null) {return ;}
            	else if(val == 1) {return '理事会主席';}
            	else if(val == 2) {return '理事会荣誉理事长';}
            	else if(val == 3) {return '理事会特别顾问';}
            	else if(val == 4) {return '理事会理事长';}
            	else if(val == 5) {return '理事';}
            }">会员职称</th>

            <th data-options="field:'persionsummary',width:300,align:'center'">个人简介</th>
			<th data-options="field:'companysummary',width:300,align:'center'">公司简介</th>
       		<!--<th data-options="field:'status',width:60,align:'center',formatter:HONGXIN.formatStatus">是否可用</th> -->
            <%--<th data-options="field:'updatetime',width:130,align:'center',formatter:HONGXIN.formatDateTime">更新日期</th>--%>
           	<%-- <th data-options="field:'createtime',width:130,align:'center',formatter:HONGXIN.formatDateTime">发布日期</th>--%>
        </tr>
    </thead>
	</table>
	</div>
</div>
</body>
<div id="EditWindow" class="easyui-window" title="编辑数据"
	 data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/vipuser/vipuser_edit.do'" style="width:1000px;height:500px;padding:10px;" />

	<div id="mm" style="width: 120px">
		<div data-options="name:'id'">id</div>
	</div>
<script>

	/*图片*/
	function loadImg(index) {
		console.info(index.src)
		layer.open({
			type: 1,
			title:'头像信息',
			area: ['600px', '360px'],
			shadeClose: true, //点击遮罩关闭
			content: '\<\img style="padding:20px;" src='+index.src+'>\<\/img>'
		});
	}

	function doSearchArticle(value, name) {
		var options = $('#articleList').datagrid('getPager').data('pagination').options;
		
		if (value == ''){
			//参数options.pageNumber, options.pageSize
			//发送post强求
			var params = {"page":options.pageNumber,"rows":options.pageSize};
			$.post("${pageContext.request.contextPath }/admin/vipuser/list.do",params, function(oData) {
				console.info(oData);
				$('#articleList').datagrid('loadData', {
					"total" : oData.total,
					"rows" : oData.rows
				});
			},"json");
		}else{
			//参数options.pageNumber, options.pageSize
			//发送post强求
			var params = {"page":options.pageNumber,"rows":options.pageSize, id:value/* "name":name,"value":value */};
			$.post("${pageContext.request.contextPath }/admin/vipuser/list.do",params, function(oData) {
				if(oData.total == 0){
					$.messager.alert('提示','没有查询到相关内容!');
				}else{
				$('#articleList').datagrid('loadData', {
					"total" : oData.total,
					"rows" : oData.rows
				});
					
				}
			},"json");

		}
	};

    function getSelectionsIds(){
    	var articleList = $("#articleList");
    	var sels = articleList.datagrid("getSelections");
    	var ids = [];
    	for(var i in sels){
    		ids.push(sels[i].id);
    	}
    	ids = ids.join(",");
    	return ids;
    }
    
    var toolbar = [{
        text:'编辑',
        iconCls:'icon-edit',
        handler:function(){
        	var ids = getSelectionsIds();
        	if(ids.length == 0){
        		$.messager.alert('提示','必须选择一条数据才能编辑!');
        		return ;
        	}
        	if(ids.indexOf(',') > 0){
        		$.messager.alert('提示','只能选择一条数据!');
        		return ;
        	}
        	
        	$("#EditWindow").window({
            		onLoad :function(){
            			//回显基础数据
            			//获取选中行的数据
            			var data = $("#articleList").datagrid("getSelections")[0];
						console.log(data);
						data.imgUrl = data.headImg;
						data.content1 = data.persionsummary;
						data.content2 = data.companysummary;
            			$("#EditForm").form("load",data);

						HONGXIN.init({
            				//回显图片
            				"pics" : data.headImg

            			});
						var EditEditor1 ;
						var EditEditor2 ;
						$(function(){
							//实例化编辑器
							EditEditor1= HONGXIN.createEditor("#EditForm [name=content1]");
							EditEditor2= HONGXIN.createEditor("#EditForm [name=content2]");
							//初始化编辑器
						});

            			// 回显内容
						EditEditor1.html(data.persionsummary);
						EditEditor2.html(data.companysummary);

            		}
            		
            		}
            	).window("open");
        	
        	
        	
        }
    },{
        text:'删除',
        iconCls:'icon-cancel',
        handler:function(){
        	var ids = getSelectionsIds();
        	if(ids.length == 0){
        		$.messager.alert('提示','未选中数据!');
        		return ;
        	}
        	$.messager.confirm('确认','确定删除ID为 '+ids+' 的数据吗？',function(r){
        	    if (r){
        	    	var params = {"ids":ids};
                	$.post("${pageContext.request.contextPath }/admin/vipuser/delete.do",params, function(data){
            			if(data.status == 200){
            				$.messager.alert('提示',data.data,undefined,function(){
            					$("#articleList").datagrid("reload");
            				});
            			}else{
            				$.messager.alert('提示',data.data,undefined,function(){
            					$("#articleList").datagrid("reload");
            				});
            			
            			}
            		},'json');
        	    }
        	});
        }
    }];
    
    


</script>